<?php
class BookController extends BaseController
{	
	//TODO:后期把标题, 中英文的内容分离开来
	public function actionIndex(){
		$this->books = obj('Book')->book_define;
		$this->display('book_index.tpl');
	}
	
	//具体一本书的目录页面
	public function action_catalog(){
		//TODO: 分页
		//$per_count = 30;
		//$p = empty($_GET['p'])? 1 : (int) $_GET['p'];
	
		$book_id = (int)$_GET['book_id'];
		if(0 === $book_id) {$this->to( URL . 'book');}
		//$book = obj('Book')->get_book($book_id,'book_id,item_name,book_title,title,title_en');
		// $book = @$this->book_define[$book_id];
		$book = obj('Book')->book_define[$book_id];
		if(empty($book)) {$this->to( URL . 'book');}
		
		$this->power = obj('Book')->power();
		$time = time();
		$catalog = obj('Book')->select("flag=1 and cr_time<$time",'section_id,item_name,title,title_en','id asc',1000);
		if($this->power) {
			$this->hide_catalog = obj('Book')->select("flag!=1 or cr_time>$time",'section_id,item_name,title,title_en','id asc',300);
		}
		$this->book = $book;
		$this->catalog = $catalog;
		$this->display('book_catalog.tpl');
	}
	
	//章节信息页面
	public function action_detail(){
		//TODO: 中英文书的处理  翻译的处理
		$book_id = (int)$_GET['book_id'];
		$id = (int)$_GET['id'];
		$content = obj('Book')->find(array('book_id'=>$book_id,'section_id'=>$id));
		if(empty($content)) {$this->to( URL . 'book/' . $book_id);}
		//var_dump($content);
		$this->content = $content;
		$this->display('book_detail.tpl');
	}
	
}